clear

forvalue i=1990/2020 {
use income_b1990.dta,clear
quietly keep if year==`i'

qui gen hhfaminc_1990 = 1 if hhincome_1990<3000
qui	replace hhfaminc_1990 = 2 if hhincome_1990>=3000 & hhincome_1990<4000
qui	replace hhfaminc_1990 = 3 if hhincome_1990>=4000 & hhincome_1990<5000
qui	replace hhfaminc_1990 = 4 if hhincome_1990>=5000 & hhincome_1990<6000
qui	replace hhfaminc_1990 = 5 if hhincome_1990>=6000 & hhincome_1990<7500
qui	replace hhfaminc_1990 = 7 if hhincome_1990>=7500 & hhincome_1990<9000
qui	replace hhfaminc_1990 = 8 if hhincome_1990>=9000 & hhincome_1990<10000
qui	replace hhfaminc_1990 = 9 if hhincome_1990>=10000 & hhincome_1990<11000
qui replace hhfaminc_1990 = 10 if hhincome_1990>=11000 & hhincome_1990<12500
qui replace hhfaminc_1990 = 12 if hhincome_1990>=12500 & hhincome_1990<14000
qui replace hhfaminc_1990 = 13 if hhincome_1990>=14000 & hhincome_1990<15000
qui replace hhfaminc_1990 = 14 if hhincome_1990>=15000 & hhincome_1990<17500
qui replace hhfaminc_1990 = 15 if hhincome_1990>=17500 & hhincome_1990<20000
qui replace hhfaminc_1990 = 16 if hhincome_1990>=20000 & hhincome_1990<22500
qui replace hhfaminc_1990 = 17 if hhincome_1990>=22500 & hhincome_1990<25000
qui replace hhfaminc_1990 = 18 if hhincome_1990>=25000 & hhincome_1990<27500
qui replace hhfaminc_1990 = 19 if hhincome_1990>=27500 & hhincome_1990<30000
qui replace hhfaminc_1990 = 20 if hhincome_1990>=30000 & hhincome_1990<32500
qui replace hhfaminc_1990 = 21 if hhincome_1990>=32500 & hhincome_1990<35000
qui replace hhfaminc_1990 = 22 if hhincome_1990>=35000 & hhincome_1990<40000
qui replace hhfaminc_1990 = 23 if hhincome_1990>=40000 & hhincome_1990<50000
qui replace hhfaminc_1990 = 24 if hhincome_1990>=50000 & hhincome_1990<75000
qui replace hhfaminc_1990 = 25 if hhincome_1990>=75000 & hhincome_1990!=.
	
qui collapse (sum) asecfwt (mean)hhincome_1990, by(hhfaminc_1990)
qui rename asecfwt hh_count
qui egen sumhh=total(hh_count)
qui gen weight=hh_count/sumhh
quietly sgini hhincome_1990 [aweight=weight]
quietly return list
di `i',r(coeff)
}

**FIGURE A2

***plot division mean

clear
use recs_1990
capture drop if kwh==999999

bysort division: egen sumhh=total(nweight)
bysort division: gen weight=nweight/sumhh
bysort division: egen meankwh=total(weight*kwh)

 collapse meankwh,by(division)
 
 
 
 
 *** FIGURE A3
 

clear
use income_b1990.dta

forvalues i=1990/2020 {
use income_b1990.dta

* create real income groups

	gen hhfaminc_1990 = 1 if hhincome_1990<3000
	replace hhfaminc_1990 = 2 if hhincome_1990>=3000 & hhincome_1990<4000
	replace hhfaminc_1990 = 3 if hhincome_1990>=4000 & hhincome_1990<5000
	replace hhfaminc_1990 = 4 if hhincome_1990>=5000 & hhincome_1990<6000
	replace hhfaminc_1990 = 5 if hhincome_1990>=6000 & hhincome_1990<7500
	replace hhfaminc_1990 = 7 if hhincome_1990>=7500 & hhincome_1990<9000
	replace hhfaminc_1990 = 8 if hhincome_1990>=9000 & hhincome_1990<10000
	replace hhfaminc_1990 = 9 if hhincome_1990>=10000 & hhincome_1990<11000
	replace hhfaminc_1990 = 10 if hhincome_1990>=11000 & hhincome_1990<12500
	replace hhfaminc_1990 = 12 if hhincome_1990>=12500 & hhincome_1990<14000
	replace hhfaminc_1990 = 13 if hhincome_1990>=14000 & hhincome_1990<15000
	replace hhfaminc_1990 = 14 if hhincome_1990>=15000 & hhincome_1990<17500
	replace hhfaminc_1990 = 15 if hhincome_1990>=17500 & hhincome_1990<20000
	replace hhfaminc_1990 = 16 if hhincome_1990>=20000 & hhincome_1990<22500
	replace hhfaminc_1990 = 17 if hhincome_1990>=22500 & hhincome_1990<25000
	replace hhfaminc_1990 = 18 if hhincome_1990>=25000 & hhincome_1990<27500
	replace hhfaminc_1990 = 19 if hhincome_1990>=27500 & hhincome_1990<30000
	replace hhfaminc_1990 = 20 if hhincome_1990>=30000 & hhincome_1990<32500
	replace hhfaminc_1990 = 21  if hhincome_1990>=32500 & hhincome_1990<35000
	replace hhfaminc_1990 = 22 if hhincome_1990>=35000 & hhincome_1990<40000
	replace hhfaminc_1990 = 23 if hhincome_1990>=40000 & hhincome_1990<50000
	replace hhfaminc_1990 = 24 if hhincome_1990>=50000 & hhincome_1990<75000
	replace hhfaminc_1990 = 25 if hhincome_1990>=75000 & hhincome_1990!=.

keep if year==`i'

collapse (sum) asecfwt, by(region)
rename asecfwt hh_count

egen sumhh=total(hh_count)
gen weight=hh_count/sumhh
save `i'_cpsincome,replace
}

 
 clear
use 1990_cpsincome
rename weight weight_1990

forval i=1991/2020 {
capture drop _merge

merge 1:1 hhfaminc_1990 using `i'_cpsincome
rename weight weight_`i'
}

drop hh_count sumhh _merge
save region_overyears.dta,replace
 
 
 
 